<template>
  <el-card class="bb1">
    <div >
      <el-button @click="check()" :type="buttoncheck" :disabled="isDisable">未批改</el-button>
      <el-button @click="checked()" :type="buttonchecked" :disabled="isDisable">已批改</el-button>


      <el-table
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column :label="title" header-align="center"  >
          <el-table-column
              prop="realName"
              label="提交人">
          </el-table-column>
          <el-table-column
              prop="createTime"
              label="提交时间"
              width="220">
          </el-table-column>
          <el-table-column
              prop="systemScore"
              label="系统判分"
              width="100">
          </el-table-column>
          <el-table-column
              prop="teacherScore"
              label="老师判分"
              width="100">
          </el-table-column>
          <el-table-column
              prop="finalScore"
              label="总分"
              width="100">
          </el-table-column>

          <el-table-column
              fixed="right"
              label="操作"
              width="100">
            <template slot-scope="scope">
              <el-button @click="checking(scope.row.id,scope.row.realName)" type="text" size="medium">批改</el-button>
            </template>
          </el-table-column>

        </el-table-column>

      </el-table>
      <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pageSize"
          :total="total"
          @current-change="page">
      </el-pagination>
    </div>
  </el-card>
</template>


<script>
export default {
  data() {
    return {
      isDisable:false,
      title:this.$route.query.title,
      buttoncheck:'primary',
      buttonchecked:'',
      flag:1,
      total:null,
      pageSize:8,
      tableData: [],
    }
  },
  methods: {
    checking(id,realName){
      let ee=this.$route.query.id;
      let dd=this.$route.query.title;
      this.$router.push({
        name:'teacherCherk',
        params: {
          id: id,
          code:ee,
          title:dd,
          realName:realName
        }
      })
    },
    check(){
      const _this = this;
      _this.buttoncheck='primary';
      _this.buttonchecked='';
      _this.flag=1;
      _this.isDisable=true;
      setTimeout(() => {
        _this.isDisable=false;
      }, 1500)
      let id1 = _this.$route.query.id;
      axios.get(_this.APIurl.apiUrl.domainName + 'examPaperAnswer/getCheck/' + id1 + '/1/8').then(function(resp) {
        console.log(resp)
        _this.tableData = resp.data.data.content
        _this.total = resp.data.data.totalElements
      })
      _this.$message({
        showClose: true,
        message: '跳转到未批改界面',
        type: 'success'
      });
    },
    checked(){
      const _this = this;
      _this.buttoncheck='';
      _this.buttonchecked='primary';
      _this.flag=0;
      _this.isDisable=true;
      setTimeout(() => {
        _this.isDisable=false;
      }, 1500)
      let id1 = _this.$route.query.id;
      axios.get(_this.APIurl.apiUrl.domainName + 'examPaperAnswer/getChecked/' + id1 + '/1/8').then(function(resp) {
        console.log(resp)
        _this.tableData = resp.data.data.content
        _this.total = resp.data.data.totalElements
      })
      _this.$message({
        showClose: true,
        message: '跳转到已批改界面',
        type: 'success'
      });
    },

    page(currentPage) {
      const _this = this
      let id2 = _this.$route.query.id;
      if(_this.flag==1){
        axios.get(_this.APIurl.apiUrl.domainName + 'examPaperAnswer/getCheck/' +
            id2 + '/' + currentPage + '/8').then(function(resp) {
          console.log(resp)
          _this.tableData = resp.data.data.content
          _this.total = resp.data.data.totalElements
        })
    }else {
        axios.get(_this.APIurl.apiUrl.domainName + 'examPaperAnswer/getChecked/' +
            id2 + '/' + currentPage + '/8').then(function(resp) {
          console.log(resp)
          _this.tableData = resp.data.data.content
          _this.total = resp.data.data.totalElements
        })
      }

    }
  },
  created() {
    const _this = this;
    let id1 = _this.$route.query.id;
    axios.get(_this.APIurl.apiUrl.domainName + 'examPaperAnswer/getCheck/' + id1 + '/1/8').then(function(resp) {
      console.log(resp)
      _this.tableData = resp.data.data.content
      _this.total = resp.data.data.totalElements
    })
  }
}
</script>

<style scoped>
.bb1{
  width: 60%;
  margin-left: 300px;
}

.el-button.is-active{
  background-color: #42b983;
}

</style>
